home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Utilities / Post / Source / BitWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-01  |  9.2 KB  |  308 lines

  1. #include "PostPre.h"
  2. #include "Global.h"
  3. #include "PostWin.h"
  4.  
  5. #include <intuition/icclass.h>
  6.  
  7. BOOL    gadgets = FALSE;
  8.  
  9. struct DrawInfo    *drinfo = NULL;
  10. struct Gadget        *uparrowg = NULL, *downarrowg = NULL, *leftarrowg = NULL,
  11.                         *rightarrowg = NULL, *vertscrollg = NULL, *boopsig = NULL;
  12. struct Image        *upimage = NULL, *downimage = NULL, *leftimage = NULL,
  13.                         *rightimage = NULL;
  14.  
  15. struct TagItem    arrows2me[] = {
  16.     {GA_ID, GA_ID},
  17.     {TAG_END, }};
  18.  
  19. /* Horizontal scroll proportional gadget */
  20. struct    PropInfo    hscrollinfo =
  21. {
  22.     AUTOKNOB | FREEHORIZ | PROPNEWLOOK | PROPBORDERLESS,
  23.     -1, -1, -1, -1
  24. };
  25. struct    Image        hscrollimage;
  26. struct    Gadget    hscrollgadg =
  27. {
  28.     NULL, 0, -6, -12, 9,
  29.     GRELBOTTOM | GRELWIDTH, BOTTOMBORDER | RELVERIFY | GACT_FOLLOWMOUSE | GACT_IMMEDIATE, PROPGADGET,
  30.     (APTR)&hscrollimage, NULL, NULL, 0, (APTR)&hscrollinfo, HORIZ_SCROLLER, NULL
  31. };
  32.  
  33. /* Vertical scroll proportional gadget */
  34. struct    PropInfo    vscrollinfo =
  35. {
  36.     AUTOKNOB | FREEVERT | PROPNEWLOOK | PROPBORDERLESS,
  37.     -1, -1, -1, -1
  38. };
  39. struct    Image        vscrollimage;
  40. struct    Gadget    vscrollgadg =
  41. {
  42.     &hscrollgadg, -10, 0, 8, -7,
  43.     GRELRIGHT | GRELHEIGHT, RIGHTBORDER | RELVERIFY | GACT_FOLLOWMOUSE | GACT_IMMEDIATE, PROPGADGET,
  44.     (APTR)&vscrollimage, NULL, NULL, 0, (APTR)&vscrollinfo, VERT_SCROLLER, NULL
  45. };
  46.  
  47. struct    Menu        *menu0=NULL, *menu1=NULL, *menu2=NULL;
  48. struct    Process    *process;
  49. struct    Window    *syswindow=NULL;
  50.  
  51. void    openwindow(void)
  52. {
  53.     UWORD        hidden;
  54.     struct    Gadget *tmpgad;
  55.     int        sysi_size, sysi_aupheight, sysi_ariwidth, sysi_vscwidth;
  56.  
  57.     GetVisual();
  58.     menu0 = CreateMenus(MenuNewMenu, TAG_END);
  59.     LayoutMenus(menu0, my_VisualInfo, GTMN_NewLookMenus, TRUE, TAG_END);
  60.     menu1 = menu0->NextMenu;
  61.     menu2 = menu1->NextMenu;
  62.  
  63.     if(Options.OutputWnd.WndWidth > Options.PostOpts.width)
  64.         Options.OutputWnd.WndWidth = Options.PostOpts.width;
  65.     if(Options.OutputWnd.WndHeight > Options.PostOpts.height)
  66.         Options.OutputWnd.WndHeight = Options.PostOpts.height;
  67.     OutputWnd = OpenWindowTags(NULL,
  68.             WA_Left,                Options.OutputWnd.WndLeft,
  69.             WA_Top,                Options.OutputWnd.WndTop,
  70.             WA_InnerWidth,        Options.OutputWnd.WndWidth,
  71.             WA_InnerHeight,    Options.OutputWnd.WndHeight,
  72.             WA_MinWidth,        100,
  73.             WA_MaxWidth,        Options.PostOpts.width,
  74.             WA_MinHeight,        100,
  75.             WA_MaxHeight,        Options.PostOpts.height,
  76.             WA_AutoAdjust,        TRUE,
  77.             WA_IDCMP,            IDCMP_REFRESHWINDOW | IDCMP_NEWSIZE |
  78.                                     IDCMP_GADGETUP | IDCMP_GADGETDOWN |
  79.                                     IDCMP_IDCMPUPDATE | IDCMP_CLOSEWINDOW |
  80.                                     IDCMP_MOUSEMOVE | IDCMP_SIZEVERIFY |
  81.                                     IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW |
  82.                                     IDCMP_MENUVERIFY | IDCMP_CHANGEWINDOW | 
  83.                                     IDCMP_MENUPICK | IDCMP_RAWKEY | IDCMP_VANILLAKEY,
  84.             WA_Flags,            WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  85.                                     WFLG_CLOSEGADGET | WFLG_SIMPLE_REFRESH |
  86.                                     WFLG_ACTIVATE | WFLG_SIZEGADGET |
  87.                                     WFLG_SIZEBRIGHT | WFLG_SIZEBBOTTOM,
  88.             WA_Title,            (ULONG) windowtitle,
  89.             WA_ScreenTitle,    (ULONG) windowtitle,
  90.             WA_PubScreen,        (ULONG) screen,
  91.             WA_NewLookMenus,    TRUE,
  92.             WA_Zoom,                (ULONG) &(Options.OutputWnd.WndZoomLeft),
  93.             TAG_DONE);
  94.     if (OutputWnd == NULL)
  95.     {
  96.         okmsg("can't open window");
  97.         errorende();
  98.         exit(20);
  99.     }
  100.  
  101. /* Locate the visible part of the bitmap within its window, adjusting    *
  102.  * for the borders                                                                         */
  103.  
  104.     winxbase = OutputWnd->BorderLeft;
  105.     winybase = OutputWnd->BorderTop;
  106.     winxsize = OutputWnd->Width - OutputWnd->BorderLeft - OutputWnd->BorderRight;
  107.     winysize = OutputWnd->Height - OutputWnd->BorderTop-OutputWnd->BorderBottom;
  108. /*    winxpos = 0;
  109.     winypos = Options.PostOpts.height - winysize;*/
  110.  
  111.     WindowLimits(OutputWnd, 100, 100,
  112.         Options.PostOpts.width + OutputWnd->BorderRight + OutputWnd->BorderLeft,
  113.         Options.PostOpts.height + OutputWnd->BorderTop + OutputWnd->BorderBottom);
  114.  
  115.     if(OutputWnd->BorderRight <= 13)
  116.     {
  117.         sysi_size        = SYSISIZE_LOWRES;
  118.         sysi_aupheight    = 11;
  119.         sysi_ariwidth    = 16;
  120.         sysi_vscwidth    = 7;
  121.     }
  122.     else
  123.     {
  124.         sysi_size = SYSISIZE_MEDRES;
  125.         sysi_aupheight    = 11;
  126.         sysi_ariwidth    = 16;
  127.         sysi_vscwidth    = 10;
  128.     }
  129.     vscrollgadg.LeftEdge = -OutputWnd->BorderRight + 1 + (OutputWnd->BorderRight - sysi_vscwidth) / 2;
  130.     vscrollgadg.TopEdge = OutputWnd->BorderTop + 1;
  131.     vscrollgadg.Height = -OutputWnd->BorderTop - OutputWnd->BorderBottom - 2 * sysi_aupheight - 2;
  132.     vscrollgadg.Width = sysi_vscwidth;
  133.  
  134.     hscrollgadg.LeftEdge = OutputWnd->BorderLeft;
  135.     hscrollgadg.TopEdge = -OutputWnd->BorderBottom + 3;
  136.     hscrollgadg.Height =  OutputWnd->BorderBottom - 4;
  137.     hscrollgadg.Width = -OutputWnd->BorderLeft - OutputWnd->BorderRight - 2 * sysi_ariwidth - 1;
  138.  
  139.     hidden = max(Options.PostOpts.width - winxsize, 0);
  140.     if(winxpos > hidden) winxpos = hidden;
  141.     if(hidden > 0)
  142.     {
  143.         hscrollinfo.HorizBody = (UWORD) (((ULONG) winxsize * MAXBODY) / (Options.PostOpts.width));
  144.         hscrollinfo.HorizPot = (UWORD) (((ULONG) winxpos * MAXBODY) / hidden);
  145.     }
  146.     else
  147.     {
  148.         hscrollinfo.HorizBody = MAXBODY;
  149.         hscrollinfo.HorizPot = 0;
  150.     }
  151.     hidden = max(Options.PostOpts.height - winysize, 0);
  152.     if(winypos > hidden) winypos = hidden;
  153.     if(hidden > 0)
  154.     {
  155.         vscrollinfo.VertBody = (UWORD) (((ULONG) winysize * MAXBODY) / (Options.PostOpts.height));
  156.         vscrollinfo.VertPot = (UWORD) (((ULONG) winypos * MAXBODY) / hidden);
  157.     }
  158.     else
  159.     {
  160.         vscrollinfo.VertBody = MAXBODY;
  161.         vscrollinfo.VertPot= 0;
  162.     }
  163.     AddGadget(OutputWnd, &hscrollgadg, -1);
  164.     AddGadget(OutputWnd, &vscrollgadg, -1);
  165.     RefreshGadgets(&hscrollgadg, OutputWnd, NULL);
  166.  
  167.     drinfo = GetScreenDrawInfo(OutputWnd->WScreen);
  168.     upimage = (struct Image *) NewObject( NULL, "sysiclass",
  169.                 SYSIA_Size, sysi_size, SYSIA_Which, UPIMAGE,
  170.                 SYSIA_DrawInfo, (ULONG) drinfo, TAG_END );
  171.     downimage = (struct Image *) NewObject( NULL, "sysiclass",
  172.                 SYSIA_Size, sysi_size, SYSIA_Which, DOWNIMAGE,
  173.                 SYSIA_DrawInfo, (ULONG) drinfo, TAG_END );
  174.     leftimage = (struct Image *) NewObject( NULL, "sysiclass",
  175.                 SYSIA_Size, sysi_size, SYSIA_Which, LEFTIMAGE,
  176.                 SYSIA_DrawInfo, (ULONG) drinfo, TAG_END );
  177.     rightimage = (struct Image *) NewObject( NULL, "sysiclass",
  178.                 SYSIA_Size, sysi_size, SYSIA_Which, RIGHTIMAGE,
  179.                 SYSIA_DrawInfo, (ULONG) drinfo, TAG_END );
  180.  
  181.     tmpgad = (struct Gadget *) &boopsig;
  182.     uparrowg = (struct Gadget *) NewObject( NULL, "buttongclass",
  183.                 GA_IMAGE,     (ULONG) upimage, GA_ID, GAD_UP,
  184.                 ICA_TARGET, ICTARGET_IDCMP, ICA_MAP, (ULONG) &arrows2me[0],
  185.                 GA_PREVIOUS, (ULONG) tmpgad, /*GA_RELVERIFY, TRUE, */GA_IMMEDIATE, TRUE,
  186.                 GA_RelRight, -OutputWnd->BorderRight + 1, GA_RelBottom, -OutputWnd->BorderBottom - 2*sysi_aupheight + 1, TAG_END);
  187.     downarrowg = (struct Gadget *) NewObject( NULL, "buttongclass",
  188.                 GA_IMAGE, (ULONG) downimage, GA_ID, GAD_DOWN,
  189.                 ICA_TARGET, ICTARGET_IDCMP, ICA_MAP, (ULONG) &arrows2me[0],
  190.                 GA_PREVIOUS, (ULONG) tmpgad, /*GA_RELVERIFY, TRUE, */GA_IMMEDIATE, TRUE,
  191.                 GA_RelRight, -OutputWnd->BorderRight + 1, GA_RelBottom, -OutputWnd->BorderBottom - sysi_aupheight + 1, TAG_END );
  192.     leftarrowg = (struct Gadget *) NewObject( NULL, "buttongclass",
  193.                 GA_IMAGE,     (ULONG) leftimage, GA_ID, GAD_LEFT,
  194.                 ICA_TARGET, ICTARGET_IDCMP, ICA_MAP, (ULONG) &arrows2me[0],
  195.                 GA_PREVIOUS, (ULONG) tmpgad, /*GA_RELVERIFY, TRUE, */GA_IMMEDIATE, TRUE,
  196.                 GA_RelRight, -OutputWnd->BorderRight - 2 * sysi_ariwidth + 1, GA_RelBottom, -OutputWnd->BorderBottom + 1, TAG_END);
  197.     rightarrowg = (struct Gadget *) NewObject( NULL, "buttongclass",
  198.                 GA_IMAGE,     (ULONG) rightimage, GA_ID, GAD_RIGHT,
  199.                 ICA_TARGET, ICTARGET_IDCMP, ICA_MAP, (ULONG) &arrows2me[0],
  200.                 GA_PREVIOUS, (ULONG) tmpgad, /*GA_RELVERIFY, TRUE, */GA_IMMEDIATE, TRUE,
  201.                 GA_RelRight, -OutputWnd->BorderRight - sysi_ariwidth + 1, GA_RelBottom, -OutputWnd->BorderBottom + 1, TAG_END);
  202.  
  203.     if(!(drinfo && upimage && downimage && leftimage && rightimage &&
  204.         downarrowg && uparrowg && leftarrowg && rightarrowg))
  205.     {
  206.         okmsg("can't get BOOPSI images & gadgets!");
  207.         errorende();
  208.         exit(20);
  209.     }
  210.     gadgets = TRUE;
  211.     AddGList(OutputWnd, boopsig, -1, -1, NULL);
  212.     RefreshGList(boopsig, OutputWnd, NULL, -1);
  213.  
  214.     process = (struct Process *) FindTask(NULL);
  215.     syswindow = (struct Window *) process->pr_WindowPtr;
  216.     process->pr_WindowPtr = (APTR) OutputWnd;
  217.     if(pubscrcontext.ps_lock)
  218.     {
  219.         UnlockPubScreen(NULL, pubscrcontext.pubscreen);
  220.         pubscrcontext.ps_lock = FALSE;
  221.     }
  222.     SetMenuStrip(OutputWnd, menu0);
  223.     setmenu();
  224.     blit_to_window = TRUE;
  225. }
  226.  
  227. void    closewindow(void)
  228. {
  229.     Forbid();
  230.     blit_to_window = FALSE;
  231.     if(intmsg)
  232.     {
  233.         do
  234.         {
  235.             ReplyMsg((struct Message *) intmsg);
  236.         } while( intmsg = (struct IntuiMessage *) GetMsg(OutputWnd->UserPort));
  237.     }
  238.     if(menu0)
  239.     {
  240.         ClearMenuStrip(OutputWnd);
  241.         FreeMenus(menu0);
  242.         menu0 = NULL;
  243.     }
  244.     if(gadgets)
  245.     {
  246.         RemoveGList(OutputWnd, boopsig, -1);
  247.         boopsig = NULL;
  248.         gadgets = FALSE;
  249.     }
  250.     if(drinfo)
  251.     {
  252.         FreeScreenDrawInfo(OutputWnd->WScreen, drinfo);
  253.         drinfo = NULL;
  254.     }
  255.     if(uparrowg)
  256.     {
  257.         DisposeObject(uparrowg);
  258.         uparrowg = NULL;
  259.     }
  260.     if(downarrowg)
  261.     {
  262.         DisposeObject(downarrowg);
  263.         downarrowg = NULL;
  264.     }
  265.     if(leftarrowg)
  266.     {
  267.         DisposeObject(leftarrowg);
  268.         leftarrowg = NULL;
  269.     }
  270.     if(rightarrowg)
  271.     {
  272.         DisposeObject(rightarrowg);
  273.         rightarrowg = NULL;
  274.     }
  275.     if(upimage)
  276.     {
  277.         DisposeObject(upimage);
  278.         upimage = NULL;
  279.     }
  280.     if(downimage)
  281.     {
  282.         DisposeObject(downimage);
  283.         downimage = NULL;
  284.     }
  285.     if(leftimage)
  286.     {
  287.         DisposeObject(leftimage);
  288.         leftimage = NULL;
  289.     }
  290.     if(rightimage)
  291.     {
  292.         DisposeObject(rightimage);
  293.         rightimage = NULL;
  294.     }
  295.  
  296.     if (OutputWnd)
  297.     {
  298.         process->pr_WindowPtr = (APTR) syswindow;
  299.         CloseWindow(OutputWnd);
  300.         OutputWnd = NULL;
  301.     }
  302.     if(pubscrcontext.got_pens)
  303.     {
  304.         ReleaseNeededPens(&pubscrcontext);
  305.     }
  306.     FreeVisual();
  307.     Permit();
  308. }